package mess;

public class LeeCode_58 {
    public static void main(String[] args) {
        System.out.println(lengthOfLastWord("hello world "));
    }
    private static int lengthOfLastWord(String s) {
        int len = s.length();
        int count = 0;
        int end = 0;
        for (int i = len - 1; i >= 0; i--) {
            if (s.charAt(i) != ' '){
                end = i;
                break;
            }
        }
        for (int i = end; i >= 0; i--) {
            if (s.charAt(i) == ' ')
                break;
            count++;
        }
        return count;
    }
}
